import React, { useState, useEffect } from 'react';
import { Affix } from 'antd';
import { api, xhrPostJson } from '@/services';
import _ from 'lodash';
import './index.less';

interface FormTitleProps {
  formCode: string;
}

export const FormTitle = (props: FormTitleProps) => {
  const { formCode } = props;
  const [formData, setformData] = useState<any>({});
  useEffect(() => {
    xhrPostJson(api.modelPage, {
      mdType: 'MetaMeta',
      pageNo: 1,
      pageSize: 1000,
      queryKeys: {
        code: formCode,
      },
    }).then((res: any) => {
      if (res.success) {
        const obj: any = _.find(res.result.content, o => o.code === formCode);
        setformData(obj);
      }
    });
  }, []);
  return (
    <Affix offsetTop={70}>
      <div className="from__title">{formData?.name || ''}</div>
    </Affix>
  );
};
